<template>
  <div class="desc-wrap process">
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="[
            {
              tooltip: '处理',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record.id),
            },
          ]" />
        </template>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useRouter } from 'vue-router'
import { TableSchema, searchFormSchema } from './data';
import { getWorkList, view } from "/@/api/work/work";

export default defineComponent({
  components: { BasicTable, TableAction },
  setup() {
    //table注册
    const [registerTable] = useTable({
      api: getWorkList,
      columns: TableSchema,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        showAdvancedButton: false,
        showResetButton: false,
        autoSubmitOnEnter: true,
      },
      useSearchForm: true,
      pagination: true,
      showIndexColumn: true,
      actionColumn: {
        title: '操作',
        dataIndex: 'action',
        fixed: false,
      },
    });

    const router = useRouter();

    function handleEdit(id) {
      // router.push('/work/view/' + id);
      // 获取数据，填充表单
      view(id).then((res: any) => {
        switch (res.formType) {
          case 'CheckReason':
            console.log('CheckReason 委托依据')
            router.push('/project/reason/view/' + res.formId)
            break
          case 'CheckPlan':
            console.log('CheckPlan 采样计划')
            router.push('/project/plan/view/' + res.formId)
            break
          case 'BusinessContract':
            console.log('BusinessContract 合同登记')
            router.push('/project/contract/view/' + res.formId)
            break
          case 'ContractConfirm':
            console.log('ContractConfirm 合同确认')
            router.push('/financial/confirm/view/' + res.formId)
            break
          case 'FinancialReceived':
            console.log('FinancialReceived 合同收款')
            router.push('/financial/received/view/' + res.formId)
            break
          case 'FinancialBill':
            console.log('FinancialBill 开票申请')
            router.push('/financial/bill/view/' + res.formId)
            break
          case 'CheckDelivery':
            console.log('CheckDelivery 派工单')
            router.push('/project/delivery/view/' + res.formId)
            break       
          case 'CheckCaiYangDept':
            console.log('Step1 采样办公室')
            router.push('/project/step15/' + res.formId)
            break
          case 'CheckCaiYang':
            console.log('Step1 采样')
            router.push('/project/step1/' + res.formId)
            break
          case 'CheckShouYang':
            console.log('Step2 收样')
            router.push('/project/step2/' + res.formId)
            break
          case 'LibDispatch':
            console.log('Step3 实验派工')
            router.push('/project/step3/' + res.formId)
            break
          case 'LibAnalysis':
            console.log('Step4 实验分析')
            router.push('/project/step4/' + res.formId)
            break
          case 'LibReport':
            console.log('Step5 实验报告')
            router.push('/project/step5/' + res.formId)
            break
          case 'HandOver':
            console.log('Step6 交付')
            router.push('/project/step6/' + res.formId)
            break
          case 'CloseDept':
            console.log('Step7 办公室结算')
            router.push('/project/step7/' + res.formId)
            break
          case 'CloseFinancial':
            console.log('Step8 财务结算')
            router.push('/project/step8/' + res.formId)
            break
          case 'Archive':
            console.log('Step9 归档')
            router.push('/project/step9/' + res.formId)
            break
          case 'CheckChangDiao1':
            console.log('Step10 职业卫生场调')
            router.push('/project/step10/' + res.formId)
            break
          case 'CheckChangDiao2':
            console.log('Step11 验收场调')
            router.push('/project/step11/' + res.formId)
            break
          case 'CheckReport':
            console.log('Step12 报告编制')
            router.push('/project/step12/' + res.formId)
            break
          case 'ShowPublic':
            console.log('Step13 公示')
            router.push('/project/step13/' + res.formId)
            break
          case 'CheckService':
            console.log('Step14 现场服务')
            router.push('/project/step14/' + res.formId)
            break
          case 'LeaveCompany':
            console.log('LeaveCompany 离职交接')
            router.push('/report/FlowLeaveCompany/view/' + res.formId)
          break
            default:
            console.log('该模块还没有开发完毕')
        }
      })
    }

    return {
      registerTable,
      handleEdit
    }
  },
});
</script>

<style lang="less">
.process-list-container {
  .vben-basic-table-form-container {
    padding: 0 !important;
  }
}

.process {
  .vben-basic-table-form-container {
    .ant-form {
      margin-bottom: 0;
    }
  }
}
</style>
